package org.huawei260.TiKu.ODsuanfa;

/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 3440 【DP】2023A-寻找重复代码
 * @version: 1.0
 */
import java.util.Scanner;
public class A_2023A_3440__DP_寻找重复代码 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			String str1 = sc.nextLine();
			String str2 = sc.nextLine();

			System.out.println(getResult(str1, str2));
		}

		public static String getResult(String str1, String str2) {
			int n = str1.length();
			int m = str2.length();

			int[][] dp = new int[n + 1][m + 1];

			int max = 0;
			String ans = "";

			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					if (str1.charAt(i - 1) == str2.charAt(j - 1)) {
						dp[i][j] = dp[i - 1][j - 1] + 1;

						if (dp[i][j] > max) {
							max = dp[i][j];
							ans = str1.substring(i - max, i);
						}
					} else {
						dp[i][j] = 0;
					}
				}
			}

			return ans;
		}
	}